home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01oop.zip / ADAWKBK / SOL3-2.ADA < prev    next >
Text File  |  1992-08-25  |  1KB  |  37 lines

  1. -- Problem 3.2
  2. -- by Rick Conn
  3. with Text_IO;
  4. procedure Main is
  5.  
  6.   type CHAR_TYPE is (LOWER_CASE, UPPER_CASE, SHARP, COMMA,
  7.                      SEMICOLON, DIGIT, SOME_OTHER);
  8.  
  9.   Char_List : constant STRING := "a#B,;2c8&1";
  10.  
  11.   package Char_Type_IO is new Text_IO.Enumeration_IO (CHAR_TYPE);
  12.  
  13.   function Char_Class (Item : in CHARACTER) return CHAR_TYPE is
  14.     Result : CHAR_TYPE;
  15.   begin
  16.     case Item is
  17.       when 'A' .. 'Z' => Result := UPPER_CASE;
  18.       when 'a' .. 'z' => Result := LOWER_CASE;
  19.       when '0' .. '9' => Result := DIGIT;
  20.       when '#'        => Result := SHARP;
  21.       when ','        => Result := COMMA;
  22.       when ';'        => Result := SEMICOLON;
  23.       when others     => Result := SOME_OTHER;
  24.     end case;
  25.     return Result;
  26.   end Char_Class;
  27.  
  28. begin -- Main
  29.  
  30.   for I in Char_List'RANGE loop
  31.     Text_IO.Put ("Character " & Char_List(I) & " is of type ");
  32.     Char_Type_IO.Put (Char_Class(Char_List(I)));
  33.     Text_IO.New_Line;
  34.   end loop;
  35.  
  36. end Main;
  37.